<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">











<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>resource-processor - </title>
    <style type="text/css" media="all">
      @import url("./css/maven-base.css");
      @import url("./css/maven-theme.css");
      @import url("./css/site.css");
    </style>
    <link rel="stylesheet" href="./css/print.css" type="text/css" media="print" />
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
      </head>
  <body class="composite">
    <div id="banner">
                    <span id="bannerLeft">
    
            resource-processor
    
            </span>
                    <div class="clear">
        <hr/>
      </div>
    </div>
    <div id="breadcrumbs">
          
  

  
    
  
  
    
            <div class="xleft">
        Last Published: 2010-09-12
                      </div>
            <div class="xright">      
  

  
    
  
  
    
  </div>
      <div class="clear">
        <hr/>
      </div>
    </div>
    <div id="leftColumn">
      <div id="navcolumn">
           
  

  
    
  
  
    
                   <h5>Overview</h5>
            <ul>
              
    <li class="none">
                    <a href="project-summary.html">Summary</a>
          </li>
              
    <li class="none">
                    <a href="usage.html">usage 1.1 (old)</a>
          </li>
              
    <li class="none">
              <strong>usage 1.2</strong>
        </li>
          </ul>
              <h5>Summary</h5>
            <ul>
              
    <li class="none">
                    <a href="dependencies.html">Dependencies</a>
          </li>
              
    <li class="none">
                    <a href="source-repository.html">Source</a>
          </li>
          </ul>
                                           <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy">
            <img alt="Built by Maven" src="./images/logos/maven-feather.png"></img>
          </a>
                       
  

  
    
  
  
    
        </div>
    </div>
    <div id="bodyColumn">
      <div id="contentBox">
        <div class="section"><h2>Introduction</h2>
<p>The release 1.2 not only contains a <b>Java Annotation Processor</b> but also useful class(s) that help to manage I18N tasks</p>
</div>
<div class="section"><h2>Use MessageFactory class</h2>
<p>The framework provides a very useful MessagesFactory class that create a Proxy &quot;on-the-fly&quot; around a chosen interface. This proxy will create a bridge from interface and Resource Bundle. By convention the resource bundle file (.properties), related to a interface, must have the same name of interface and must be located in the same package</p>
<p><b>An Example</b></p>
<div class="source"><pre> //
 // I18N interface
 //
 package test;
 public interface  IMessages {

    /** this method allow to access directly to resource bundle */
    String getString( String key );

    String unknow(); 
    String fileNotFound( String fileName );
 }

 //
 // Usage
 //
 IMessages m = MessagesFactory.createInstance( IMessages.class, null);

 System.out.println( m.fileNotFound(&quot;MyFile.txt&quot;));
 System.out.println( m.unknow());

 //
 // test/IMessages_it.properties
 //
 fileNotFound=Il file {0} non e' stato trovato
 unknow=Un problema imprevisto e' accaduto. Richiedere l'intervento del supporto</pre>
</div>
</div>
<div class="section"><h2>Use GwtMessageFactory class</h2>
<p>This class provides a useful Proxy that is compliant with I18N Interface generate by GWT (2.0 and above). So we can use the same interface both on client and server side</p>
</div>
<div class="section"><h2>Generate I18N interface(s)</h2>
<p>This is an <b>OPTIONAL</b> task designed to be used joined with a <a href="http://code.google.com/p/maven-annotation-plugin/" class="externalLink">maven-annotation-plugin</a></p>
</div>
<div class="section"><h2>Usage</h2>
<p>To use processor you have to do the following steps:</p>
<ol type="1"><li>Create a file containing messages. (OPTIONAL)</li>
<li>Add dependency of processor in your POM.</li>
<li>Run processor using maven-annotation-plugin.</li>
</ol>
<ul><li><b>Create a file containing messages</b><p>The messages must be put in the properties file. This file must be <b>reachable from classpath</b> and the name of each property must be compliant with <b>java method name syntax</b> otherwise will be ignored.</p>
</li>
<li><b>Add dependency of processor in your POM</b><p>Add to your pom the following dependency</p>
<div class="source"><pre>
    &lt;dependency&gt;
          &lt;groupId&gt;org.bsc.processor&lt;/groupId&gt;
          &lt;artifactId&gt;resource-processor&lt;/artifactId&gt;
          &lt;version&gt;1.2&lt;/version&gt;
          &lt;type&gt;jar&lt;/type&gt;
    &lt;/dependency&gt;
</pre>
</div>
<p>And add repository declaration </p>
<div class="source"><pre>
&lt;repositories&gt;
    &lt;repository&gt;
      &lt;id&gt;internationalization-processor&lt;/id&gt;
      &lt;url&gt;http://internationalization-processor.googlecode.com/svn/mavenrepo&lt;/url&gt;
    &lt;/repository&gt;
&lt;/repositories&gt;
</pre>
</div>
</li>
<li><b>Run processor using maven-annotation-plugin</b></li>
</ul>
</div>
<div class="section"><h2>An Example</h2>
<div class="source"><pre>
&lt;/plugin&gt;
    &lt;plugin&gt;
      &lt;groupId&gt;org.bsc.maven&lt;/groupId&gt;
      &lt;artifactId&gt;maven-processor-plugin&lt;/artifactId&gt;
      &lt;version&gt;1.3.6&lt;/version&gt;
      &lt;executions&gt;
        &lt;execution&gt;
          &lt;id&gt;process&lt;/id&gt;
          &lt;goals&gt;
            &lt;goal&gt;process&lt;/goal&gt;
          &lt;/goals&gt;
          &lt;phase&gt;generate-sources&lt;/phase&gt;
          &lt;configuration&gt;
             &lt;outputDirectory&gt;${basedir}/target/generated-sources/processor&lt;/outputDirectory&gt;          
             &lt;failOnError&gt;false&lt;/failOnError&gt;
              
             &lt;processors&gt;
                &lt;processor&gt;org.bsc.processor.implementation.ResourceProcessorInterface&lt;/processor&gt;
             &lt;/processors&gt;
             &lt;compilerArguments&gt;

                 &lt;!--
                    name of interface that will be generated
                    In this case the resource org/bsc/processor/test/Imessages.properties will be used
                 --&gt;
                -Ainterface=org.bsc.processor.test.IMessages
             &lt;/compilerArguments&gt;
          &lt;/configuration&gt;

        &lt;/execution&gt;
      &lt;/executions&gt;
    &lt;/plugin&gt;
</pre>
</div>
<p>And add the plugin repository declaration</p>
<div class="source"><pre>
&lt;pluginRepositories&gt;
    &lt;pluginRepository&gt;
      &lt;id&gt;maven-annotation-plugin&lt;/id&gt;
      &lt;url&gt;http://maven-annotation-plugin.googlecode.com/svn/trunk/mavenrepo&lt;/url&gt;
    &lt;/pluginRepository&gt;
&lt;/pluginRepositories&gt;
</pre>
</div>
</div>

      </div>
    </div>
    <div class="clear">
      <hr/>
    </div>
    <div id="footer">
      <div class="xright">&#169;  
          2010
    
          
  

  
    
  
  
    
  </div>
      <div class="clear">
        <hr/>
      </div>
    </div>
  </body>
</html>
